
<label><?php echo $field['title']; ?></label>
<?php 

$field_value = isset($field['value'])?$field['value']:(isset($field['default'])?$field['default']:"");

switch($field['type']){
	
	case 'text':
		$param_form = array(
			"name"		=> $field_name,
			"id"		=> $field_name,
			"value"		=> $field_value,
			'class'		=> 'text-input large-input'
		);
		echo form_input($param_form);
		break;
		
	case 'textarea':
		$param_form = array(
			"name"		=> $field_name,
			"id"		=> $field_name,
			"value"		=> $field_value,
			'class'		=> 'text-input',
			'rows'		=> 3
		);
		echo form_textarea($param_form);
		break;
		
	case 'select':
		//split options separated with bar
		$options=split('\|', $field['options']);
		$o_array = array();
		foreach($options as $o) {
			//split key and value if separated with =
			$op = split('=',$o);
			if(count($op)==2) {$opK=$op[0];$opV=$op[1];} else {$opK=$op[0];$opV=$op[0];}
			//store value to options array
			$o_array[$opK]=$opV;
		} 
		
		echo form_dropdown($field_name, $o_array, set_value($field_name, $field_value));
		echo "<br/>\n";
		break;
	
	case 'radio':
		//split options separated with bar
		$options=split('\|', $field['options']);
		//$o_array = array();
		foreach($options as $index=>$o) {
			//split key and value if separated with =
			$op = split('=',$o);
			if(count($op)==2) {$opK=$op[0];$opV=$op[1];} else {$opK=$op[0];$opV=$op[0];}
			//store value to options array
			
			if(is_numeric($opK)){
				$opK = (int)$opK;
			}
			if(is_numeric($field_value)){
				$field_value = (int)$field_value;
			}
			
			$checked = ($opK==$field_value)?true:false;
			$o_array=array(
				'name'=>$field_name,
				'id'=>$field_name,
				'value'=>$opK,
				'checked'=>$checked
				);
				
			echo form_radio($o_array).$opV.'&nbsp;';
			
			if($index < count($options) -1){
				//echo "<br/>\n";
			}
		} 
		echo "<br/>\n";
		break;
		
	case 'file':
		$param_form = array(
			"name"		=> $field_name,
			"id"		=> $field_name
		);
		echo form_upload($param_form) . "<br/>";
		if($field_value != NULL && $field_value != ""){
			echo "<small>Fichero: <a href='".site_url($field_value)."' target='_blank'>$field_value</a></small><br/>";
		}
		break;
		
	default:
		echo "Tipo no soportado";
	
}
?>

<?php if(isset($field['description'])): ?>
	<small><?php echo $field['description']; ?></small>
<?php endif; ?>